package com.rz.htk.template.controller;

import com.rz.core.resp.ResultResp;
import com.rz.htk.order.service.IOrderService;
import com.rz.htk.template.entity.vo.ExportParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;

/**
 * @ClassName TemplateController
 * @Description 模板controller
 * @Author maweiyue
 * @Date 2019/4/17 20:37
 */
@RestController
@RequestMapping("/excelExport")
public class ExcelExportController {

    @Resource
    private IOrderService orderService;

    /**
     * 报关单导出接口
     * @param exportParam 导出信息参数
     * @param response
     * @return
     * @throws Exception
     */
    @PostMapping("exportCustomsDeclaration")
    public ResultResp export(@RequestBody ExportParam exportParam, HttpServletResponse response) throws Exception{
        OutputStream output = response.getOutputStream();
        response.reset();
        response.setHeader("Content-disposition", "attachment; filename=temp.xls");
        response.setContentType("application/msexcel");
        orderService.exportCustomsDeclaration(exportParam, output);
        output.flush();
        output.close();
        return null;
    }
}
